package com.itheima.atte.controller;


import com.itheima.atte.dto.AttendGroupDTO;
import com.itheima.atte.service.IAttendGroupService;
import com.itheima.common.vo.PageResult;
import com.itheima.common.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 考勤组信息表 考勤-考勤组信息表 前端控制器
 * </p>
 *
 * @author itheima
 * @since 2020-12-22
 */
@RestController
public class AttendGroupController {

    @Autowired
    private IAttendGroupService attendGroupService;

    /**
     * PC:分页获得考勤组列表
     */
    @GetMapping(value = "/atte/attendGroup")
    public Result<PageResult<AttendGroupDTO>> queryByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize
    ) throws Exception {
        return Result.success(attendGroupService.queryByPage(page, pageSize));
    }


    /**
     * PC:添加考勤组
     */
    @PostMapping(value = "/atte/attendGroup")
    public Result insertAttendGroup(@RequestBody AttendGroupDTO attendGroupDTO) throws Exception {
        attendGroupService.saveAttendGroup(attendGroupDTO);
        return Result.success();
    }


    /**
     * 通过员工id获取相应考勤组
     * 移动端
     */
    @GetMapping(value = "/atte/getAttendGroupByUserId")
    public Result<AttendGroupDTO> queryAttendGroupByCompanyUserId(@RequestParam("id") Long companyUserId) throws Exception {
        return Result.success(attendGroupService.queryAttendGroupByCompanyUserId(companyUserId));
    }
}

